<?php
class profile_model extends CI_Model
{
    public $id;
    public $full_name;
    public $position;
    public $company;
    public $image_profile;
    public $created_date;
    public $skills;
    public $interested;
    public $phone_number;
    public $email;
    public $birthday;
    public $location;

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM profile");
        return $this->to_domain_models($query->result());
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM profile WHERE id = ?",array($id));
        return $this->to_domain_model($query->row());
    }

    // -------------------------------------------------------------------------------- PRIVATE METHOD

    // Private method
    public function __get($key)
    {
        if(method_exists($this,$MethodName='get_'.$key)) return $this->$MethodName();
        $CI =& get_instance();
        return $CI->$key;
    }

    // Private method
    public function to_domain_models($array)
    {
        $result = array();
        foreach($array as $item)
        {
            $result[] = $this->to_domain_model($item);
        }
        return $result;
    }

    // Private method
    public function to_domain_model($item)
    {
        $model = new profile_model();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->full_name = isset($item->full_name) ? $item->full_name : '' ;
        $model->position = isset($item->position) ? $item->position : '' ;
        $model->company = isset($item->company) ? $item->company : '';
        $model->image_profile = isset($item->image_profile) ? $item->image_profile : '';
        $model->created_date = isset($item->created_date) ? $item->created_date: '';
        //-------------------------
        $model->location = isset($item->location) ? $item->location: '';
        $model->birthday = isset($item->birthday) ? $item->birthday: '';
        $model->email = isset($item->email) ? $item->email: '';
        $model->phone_number = isset($item->phone_number) ? $item->phone_number: '';
        $model->interested = isset($item->interested) ? $item->interested: '';
        $model->skills = isset($item->skills) ? $item->skills: '';
        return $model;
    }
}